package com.openisle.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OpenApiConfig {

    @Value("${springdoc.info.title}")
    private String title;

    @Value("${springdoc.info.description}")
    private String description;

    @Value("${springdoc.info.version}")
    private String version;

    @Value("${springdoc.info.scheme}")
    private String scheme;

    @Value("${springdoc.info.header}")
    private String header;

    @Bean
    public OpenAPI openAPI() {
        SecurityScheme securityScheme = new SecurityScheme()
			.type(SecurityScheme.Type.HTTP)
			.scheme(scheme.toLowerCase())
			.bearerFormat("JWT")
			.in(SecurityScheme.In.HEADER)
			.name(header);

        return new OpenAPI()
                .info(new Info()
					.title(title)
					.description(description)
					.version(version))
                .components(new Components()
					.addSecuritySchemes("JWT", securityScheme))
                .addSecurityItem(new SecurityRequirement().addList("JWT"));
    }
}
